#include "opencv.h"


GLuint loadTextureIpl(IplImage *image) 
{

	GLuint text;
 
	if (image==NULL) return -1;

	glGenTextures(1, &text);
 
	glBindTexture( GL_TEXTURE_2D, text ); //bind the texture to it's array
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
 
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height,0, GL_BGR, GL_UNSIGNED_BYTE, image->imageData);
	return text;
 
}

SE_image *SE_cv_image_load(IplImage *image)
{
	
	SE_image *img;
	img = (SE_image*)malloc(sizeof(SE_image));
	
//	SDL_Surface *temp; 

//	if((temp = IMG_Load(path)) == NULL)
//	{
//		printf("error, no se pudo cargar la imagen");
//	}
	
	img->texture = loadTextureIpl(image);

	img->w = image->width;
	img->h = image->height;
	
	img->x = 0;
	img->y = 0;

	
//	SDL_FreeSurface(temp);
	return img;
}

void SE_cv_image_unload(SE_image *image)
{
	glDeleteTextures( 1,&image->texture );
	free(image);

}

